import { getUserInfoAPI } from '@/api'
import Vue from 'vue'
import Vuex from 'vuex'
import createPresistedStaed from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: {}
  },

  getters: {
    userInfo: state => state.userInfo
  },

  mutations: {
    setToken (state, token) {
      state.token = token
    },
    setUserInfo (state, val) {
      state.userInfo = val
    }
  },

  actions: {
    async getUserInfoAction (context) {
      const { data: res } = await getUserInfoAPI()
      if (res.code === 0) {
        context.commit('setUserInfo', res.data)
      }
    }
  },

  modules: {
  },

  plugins: [createPresistedStaed()]
})
